

<template>
    <div>
        <div style="height:230px;width:100%;position:relative;">
            <vxe-table :loading="loading" :data.sync="tableData" border fit :mouse-config="{selected: true}" :edit-config="{trigger: 'click', mode: 'cell',showStatus: true,showIcon:false}" height="auto" header-align="center" highlight-current-row highlight-hover-row ref="xTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe @cell-dblclick="btnConfirm">
                <vxe-table-column field="defaultratio" title=" " width="40" sortable align="center">
                </vxe-table-column>
                <vxe-table-column field="unit" title="商品单位" width="70" sortable align="center">
                </vxe-table-column>
                <vxe-table-column field="sign" title=" " width="40" sortable align="center">
                </vxe-table-column>
                <vxe-table-column field="ratio" title="换算系数" width="70" sortable align="center">
                </vxe-table-column>
                <vxe-table-column field="miniunit" title="最小单位" width="70" sortable align="center">
                </vxe-table-column>
            </vxe-table>
        </div>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
    props: { itemlotnoid: { type: [Number, String], default: 0 }, itemid: { type: [Number, String], default: 0 }, warehouseid: { type: [Number, String], default: 0 }, price: { type: [String, Number] }, fromunit: { type: String }, onlychangeunit: { type: Boolean, default: true } },
    data() {
        return {
            loading: false,
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            dialogunit: false,
            selectConfig: { tigger: "row" },
            tableData: [],
        };
    },
    created() {
        this.InitPage(); //初始化主列表
        //this.getinitdata(); //初始化下拉框的数据
    },
    watch: {},
    computed: {},
    mounted() {},
    updated() {},
    methods: {
        InitPage() {
            this.loading = true;
            this.$tool
                .request({
                    url: "ucent/ddl",
                    method: "post",
                    data: {
                        action: "invitemunitratio",
                        itemid: this.itemid,
                        itemlotnoid: this.itemlotnoid,
                    },
                })
                .then((res) => {
                    this.dialogunit = true;
                    this.tableData = res.data;
                    if (res.data.length > 0) {
                        this.$refs.xTable.setCurrentRow(res.data[0]);
                    } else {
                        this.tableData = [];
                        this.$refs.xTable.setCurrentRow(null);
                    }
                    this.loading = false;
                })
                .catch((e) => {
                    this.$alert(e, "提示");
                    this.loading = false;
                });
        },
        btnConfirm({ row, column }) {
            if (this.onlychangeunit) {
                this.$emit("change", row);
                this.$emit("changeObj", {code:'', name:'', row:row});
            } else {
                this.$tool
                    .request({
                        url: "ucent/ddl",
                        method: "post",
                        data: {
                            action: "getqtyByRatio",
                            itemid: this.itemid,
                            warehouseid: this.warehouseid,
                            itemlotnoid: this.itemlotnoid,
                            price: this.price,
                            fromunit: this.fromunit,
                            tounit: row.unit,
                        },
                    })
                    .then((res) => {
                        row.price = res.price;
                        row.stockqty = res.stockqty;
                        this.$emit("change", row);
                        this.$emit("changeObj", {code:'', name:'', row:row});
                        this.loading = false;
                    })
                    .catch((e) => {
                        this.$alert(e, "提示");
                        this.loading = false;
                    });
            }
        },
        btnCancel() {
            this.$emit("cancel");
        },
        currentChangeEvent({ row }) {
            this.curRow = row;
        },
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 35px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 40px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 400px;
    left: 0px;
    right: 0px;
    overflow: auto;
}
.table1style tr td {
    padding: 0px 2px 0px 2px;
    font-size: 12px;
}
</style>